import os
import sys

testlibDirectory = sys.path[0] + '/testlib'

buildCommands = {
    '.cpp' : 'g++ {} -I' + testlibDirectory + ' -std=c++17 -O2 -o {}',
    '.py' : 'cp {} {}.py'
}

executeSuffix = {
    '.cpp' : '',
    '.py' : '.py'
}

debugBuildCommands = {
    '.cpp' : 'g++ {} -Wall -fsanitize=address,undefined -I' + testlibDirectory + ' -std=c++17 -O2 -o {}',
    '.py' : 'cp {} {}.py'
}

sourceToBuild = {}

def buildTo(source, targetDirectory):
    for key, value in buildCommands.items():
        if source.endswith(key):
            if source in sourceToBuild and sourceToBuild[source] == targetDirectory + executeSuffix[key]:
                print(source + ' already compiled. skipped.')
                return
            print('\033[1;94mCompiling\033[0m ' + value.format(source, targetDirectory))
            os.system(value.format(source, targetDirectory))
            sourceToBuild[source] = targetDirectory + executeSuffix[key]
            return True
    print('Failed to compile {}: unrecgonized file type.'.format(source))
    return False

def build(source):
    buildTo(source, 'build/' + source.split('/')[-1].split('.')[0])

def findBuild(source):
    if source not in sourceToBuild:
        return 'NOT FOUND'
    return sourceToBuild[source]

if __name__ == '__main__':
    source = input()
    build(source)